package com.muyu.product.domain.model;

import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.product.domain.AttributeGroup;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author DongZl
 * @description: 共有属性组
 * @Date 2024-3-6 下午 02:29
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class TemplateAttributeGroupModel extends BaseEntity {

    /**
     * 组名称
     */
    private String groupName;

    /**
     * 属性组下属性集合
     */
    private List<TemplateAttributeModel> attributeList;

    /**
     * 是否有效
     * @return
     */
    public boolean isEffective(){
        return StringUtils.isNotEmpty(groupName) && attributeList != null && !attributeList.isEmpty();
    }

    /**
     *
     * @param attributeGroup
     * @param attributeList
     * @return
     */
    public static TemplateAttributeGroupModel attributeGroupBuild(AttributeGroup attributeGroup,
                                                                  Function<Long, List<TemplateAttributeModel>> attributeList){
        return TemplateAttributeGroupModel.builder()
                .groupName(attributeGroup.getName())
                .attributeList(attributeList.apply(attributeGroup.getId()))
                .build();

    }
}
